class Solution {
    public int widthOfBinaryTree(TreeNode root) {

    }
    public int width(TreeNode root) {
        if(root==null) return 0;
        TreeNode curLeft=root;
        TreeNode curRight=root;
        int max=1;
        if(curLeft==root&&(root.left!=null&&root.right!=null)) {
            curLeft=root.left;
            curRight=root.right;
            max=2;
        } else {
            return max;
        }
        while((curLeft.left!=null || curLeft.right!=null)&&(curRight.left!=null || curRight.right!=null)) {
            boolean isLeft=true;
            boolean isRight=true;
            if(curLeft.left!=null) {
                curLeft=curLeft.left;
            } else {
                curLeft=curRight.right;
                isLeft=false;
            }
            if(curRight.right!=null) {
                curRight=curRight.right;
            } else {
                curRight=curRight.left;
                isRight=false;
            }
            if(isLeft==true&&isRight==true) {
                max+=2;
            } else if((isLeft==false&&isRight==true)||(isLeft==true&&isRight==false)) {
                max+=1;
            }
        }
        return max;
    }
}
public class lc662 {
}
